//
//  CustomStarButton.m
//  SameWorld(merchant)
//
//  Created by 李小朋 on 2017/3/31.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "CustomStarButton.h"

@implementation CustomStarButton

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setup {
    
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.titleLabel.font=[UIFont systemFontOfSize:14];
    [self setImage:[UIImage imageNamed:@"ic_shangjiantou"] forState:UIControlStateNormal];
    [self setImage:[UIImage imageNamed:@"ic_xiajiantou"] forState:UIControlStateSelected];
#pragma marl - 如果不添加背景颜色会出错
    self.imageView.backgroundColor = [UIColor colorWithHexString:@"#ff9900"];
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
    //计算label frame
    self.titleLabel.x=self.imageView.x;
    //计算img frame
    self.imageView.x=CGRectGetMaxX(self.titleLabel.frame)+8;
}
-(void)setTitle:(NSString *)title forState:(UIControlState)state{
    [super setTitle:title forState:state];
    [self sizeToFit];
}
-(void)setImage:(UIImage *)image forState:(UIControlState)state{
    [super setImage:image forState:state];
    [self sizeToFit];
}

@end
